﻿using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace OrganizedConfusion.Game_Objects
{
    public class CheckpointFlag : BaseObject
    {
        public bool IsActive { get; set; }

        public CheckpointFlag()
        {
            base.type = OBJ_TYPE.OBJ_FLAG;
            IsActive = false;
        }

        public override bool CheckCollision(BaseObject obj)
        {
            if (obj.Type != (int)OBJ_TYPE.OBJ_PLAYER)
                return false;

            Player user = (Player)obj;

            if (user.MyCheckpoint == this)
                return false;

            Rectangle rtnRect = Rectangle.Intersect(obj.CreateCollisionRect(), CreateCollisionRect());

            if (rtnRect.Width != 0 && rtnRect.Height != 0)
            {
                IsActive = true;

                if (user.MyCheckpoint != null)
                    user.MyCheckpoint.IsActive = false;
                user.MyCheckpoint = this;
                return true;
            }
            return false;
        }

        public override void Render(Microsoft.Xna.Framework.Graphics.SpriteBatch sb)
        {
            if(!IsActive)
                base.Render(sb);
            else
                sb.Draw(ContentsManager.Instance.Draw(Image), Position, null, Color.Green, 0.0f, Origin, 1.0f, SpriteEffects.None, 0.0f);

        }
    }
}
